home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / mac / DirectX SDK / DXSDK / include / d3dx8core.h < prev    next >
C/C++ Source or Header  |  2001-10-08  |  17KB  |  564 lines

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. //  Copyright (C) Microsoft Corporation.  All Rights Reserved.
  4. //
  5. //  File:       d3dx8core.h
  6. //  Content:    D3DX core types and functions
  7. //
  8. ///////////////////////////////////////////////////////////////////////////
  9.  
  10. #include "d3dx8.h"
  11.  
  12. #ifndef __D3DX8CORE_H__
  13. #define __D3DX8CORE_H__
  14.  
  15.  
  16.  
  17. ///////////////////////////////////////////////////////////////////////////
  18. // ID3DXBuffer:
  19. // ------------
  20. // The buffer object is used by D3DX to return arbitrary size data.
  21. //
  22. // GetBufferPointer -
  23. //    Returns a pointer to the beginning of the buffer.
  24. //
  25. // GetBufferSize -
  26. //    Returns the size of the buffer, in bytes.
  27. ///////////////////////////////////////////////////////////////////////////
  28.  
  29. typedef interface ID3DXBuffer ID3DXBuffer;
  30. typedef interface ID3DXBuffer *LPD3DXBUFFER;
  31.  
  32. // {932E6A7E-C68E-45dd-A7BF-53D19C86DB1F}
  33. DEFINE_GUID(IID_ID3DXBuffer, 
  34. 0x932e6a7e, 0xc68e, 0x45dd, 0xa7, 0xbf, 0x53, 0xd1, 0x9c, 0x86, 0xdb, 0x1f);
  35.  
  36. #undef INTERFACE
  37. #define INTERFACE ID3DXBuffer
  38.  
  39. DECLARE_INTERFACE_(ID3DXBuffer, IUnknown)
  40. {
  41.     // IUnknown
  42.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  43.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  44.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  45.  
  46.     // ID3DXBuffer
  47.     STDMETHOD_(LPVOID, GetBufferPointer)(THIS) PURE;
  48.     STDMETHOD_(DWORD, GetBufferSize)(THIS) PURE;
  49. };
  50.  
  51.  
  52.  
  53. ///////////////////////////////////////////////////////////////////////////
  54. // ID3DXFont:
  55. // ----------
  56. // Font objects contain the textures and resources needed to render
  57. // a specific font on a specific device.
  58. //
  59. // Begin -
  60. //    Prepartes device for drawing text.  This is optional.. if DrawText
  61. //    is called outside of Begin/End, it will call Begin and End for you.
  62. //
  63. // DrawText -
  64. //    Draws formatted text on a D3D device.  Some parameters are 
  65. //    surprisingly similar to those of GDI's DrawText function.  See GDI 
  66. //    documentation for a detailed description of these parameters.
  67. //
  68. // End -
  69. //    Restores device state to how it was when Begin was called.
  70. //
  71. // OnLostDevice, OnResetDevice -
  72. //    Call OnLostDevice() on this object before calling Reset() on the
  73. //    device, so that this object can release any stateblocks and video
  74. //    memory resources.  After Reset(), the call OnResetDevice().
  75. //
  76. ///////////////////////////////////////////////////////////////////////////
  77.  
  78. typedef interface ID3DXFont ID3DXFont;
  79. typedef interface ID3DXFont *LPD3DXFONT;
  80.  
  81.  
  82. // {89FAD6A5-024D-49af-8FE7-F51123B85E25}
  83. DEFINE_GUID( IID_ID3DXFont, 
  84. 0x89fad6a5, 0x24d, 0x49af, 0x8f, 0xe7, 0xf5, 0x11, 0x23, 0xb8, 0x5e, 0x25);
  85.  
  86.  
  87. #undef INTERFACE
  88. #define INTERFACE ID3DXFont
  89.  
  90. DECLARE_INTERFACE_(ID3DXFont, IUnknown)
  91. {
  92.     // IUnknown
  93.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  94.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  95.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  96.  
  97.     // ID3DXFont
  98.     STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE8* ppDevice) PURE;
  99.     STDMETHOD(GetLogFont)(THIS_ LOGFONT* pLogFont) PURE;
  100.  
  101.     STDMETHOD(Begin)(THIS) PURE;
  102.     STDMETHOD_(INT, DrawTextA)(THIS_ LPCSTR  pString, INT Count, LPRECT pRect, DWORD Format, D3DCOLOR Color) PURE;
  103.     STDMETHOD_(INT, DrawTextW)(THIS_ LPCWSTR pString, INT Count, LPRECT pRect, DWORD Format, D3DCOLOR Color) PURE;
  104.     STDMETHOD(End)(THIS) PURE;
  105.  
  106.     STDMETHOD(OnLostDevice)(THIS) PURE;
  107.     STDMETHOD(OnResetDevice)(THIS) PURE;
  108. };
  109.  
  110. #ifndef DrawText
  111. #ifdef UNICODE
  112. #define DrawText DrawTextW
  113. #else
  114. #define DrawText DrawTextA
  115. #endif
  116. #endif
  117.  
  118.  
  119. #ifdef __cplusplus
  120. extern "C" {
  121. #endif //__cplusplus
  122.  
  123. HRESULT WINAPI
  124.     D3DXCreateFont(
  125.         LPDIRECT3DDEVICE8   pDevice,
  126.         HFONT               hFont,
  127.         LPD3DXFONT*         ppFont);
  128.  
  129.  
  130. HRESULT WINAPI
  131.     D3DXCreateFontIndirect(
  132.         LPDIRECT3DDEVICE8   pDevice,
  133.         CONST LOGFONT*      pLogFont,
  134.         LPD3DXFONT*         ppFont);
  135.  
  136. #ifdef __cplusplus
  137. }
  138. #endif //__cplusplus
  139.  
  140.  
  141.  
  142.  
  143. ///////////////////////////////////////////////////////////////////////////
  144. // ID3DXSprite:
  145. // ------------
  146. // This object intends to provide an easy way to drawing sprites using D3D.
  147. //
  148. // Begin - 
  149. //    Prepares device for drawing sprites
  150. //
  151. // Draw, DrawAffine, DrawTransform -
  152. //    Draws a sprite in screen-space.  Before transformation, the sprite is
  153. //    the size of SrcRect, with its top-left corner at the origin (0,0).  
  154. //    The color and alpha channels are modulated by Color.
  155. //
  156. // End - 
  157. //     Restores device state to how it was when Begin was called.
  158. //
  159. // OnLostDevice, OnResetDevice -
  160. //    Call OnLostDevice() on this object before calling Reset() on the
  161. //    device, so that this object can release any stateblocks and video
  162. //    memory resources.  After Reset(), the call OnResetDevice().
  163. ///////////////////////////////////////////////////////////////////////////
  164.  
  165. typedef interface ID3DXSprite ID3DXSprite;
  166. typedef interface ID3DXSprite *LPD3DXSPRITE;
  167.  
  168.  
  169. // {13D69D15-F9B0-4e0f-B39E-C91EB33F6CE7}
  170. DEFINE_GUID( IID_ID3DXSprite, 
  171. 0x13d69d15, 0xf9b0, 0x4e0f, 0xb3, 0x9e, 0xc9, 0x1e, 0xb3, 0x3f, 0x6c, 0xe7);
  172.  
  173.  
  174. #undef INTERFACE
  175. #define INTERFACE ID3DXSprite
  176.  
  177. DECLARE_INTERFACE_(ID3DXSprite, IUnknown)
  178. {
  179.     // IUnknown
  180.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  181.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  182.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  183.  
  184.     // ID3DXSprite
  185.     STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE8* ppDevice) PURE;
  186.  
  187.     STDMETHOD(Begin)(THIS) PURE;
  188.  
  189.     STDMETHOD(Draw)(THIS_ LPDIRECT3DTEXTURE8  pSrcTexture, 
  190.         CONST RECT* pSrcRect, CONST D3DXVECTOR2* pScaling, 
  191.         CONST D3DXVECTOR2* pRotationCenter, FLOAT Rotation, 
  192.         CONST D3DXVECTOR2* pTranslation, D3DCOLOR Color) PURE;
  193.  
  194.     STDMETHOD(DrawTransform)(THIS_ LPDIRECT3DTEXTURE8 pSrcTexture, 
  195.         CONST RECT* pSrcRect, CONST D3DXMATRIX* pTransform, 
  196.         D3DCOLOR Color) PURE;
  197.  
  198.     STDMETHOD(End)(THIS) PURE;
  199.  
  200.     STDMETHOD(OnLostDevice)(THIS) PURE;
  201.     STDMETHOD(OnResetDevice)(THIS) PURE;
  202. };
  203.  
  204.  
  205. #ifdef __cplusplus
  206. extern "C" {
  207. #endif //__cplusplus
  208.  
  209.  
  210. HRESULT WINAPI
  211.     D3DXCreateSprite(
  212.         LPDIRECT3DDEVICE8   pDevice,
  213.         LPD3DXSPRITE*       ppSprite);
  214.  
  215. #ifdef __cplusplus
  216. }
  217. #endif //__cplusplus
  218.  
  219.  
  220.  
  221.  
  222. ///////////////////////////////////////////////////////////////////////////
  223. // ID3DXRenderToSurface:
  224. // ---------------------
  225. // This object abstracts rendering to surfaces.  These surfaces do not 
  226. // necessarily need to be render targets.  If they are not, a compatible
  227. // render target is used, and the result copied into surface at end scene.
  228. //
  229. // BeginScene, EndScene -
  230. //    Call BeginScene() and EndScene() at the beginning and ending of your
  231. //    scene.  These calls will setup and restore render targets, viewports, 
  232. //    etc.. 
  233. //
  234. // OnLostDevice, OnResetDevice -
  235. //    Call OnLostDevice() on this object before calling Reset() on the
  236. //    device, so that this object can release any stateblocks and video
  237. //    memory resources.  After Reset(), the call OnResetDevice().
  238. ///////////////////////////////////////////////////////////////////////////
  239.  
  240. typedef struct _D3DXRTS_DESC
  241. {
  242.     UINT                Width;
  243.     UINT                Height;
  244.     D3DFORMAT           Format;
  245.     BOOL                DepthStencil;
  246.     D3DFORMAT           DepthStencilFormat;
  247.  
  248. } D3DXRTS_DESC;
  249.  
  250.  
  251. typedef interface ID3DXRenderToSurface ID3DXRenderToSurface;
  252. typedef interface ID3DXRenderToSurface *LPD3DXRENDERTOSURFACE;
  253.  
  254.  
  255. // {82DF5B90-E34E-496e-AC1C-62117A6A5913}
  256. DEFINE_GUID( IID_ID3DXRenderToSurface, 
  257. 0x82df5b90, 0xe34e, 0x496e, 0xac, 0x1c, 0x62, 0x11, 0x7a, 0x6a, 0x59, 0x13);
  258.  
  259.  
  260. #undef INTERFACE
  261. #define INTERFACE ID3DXRenderToSurface
  262.  
  263. DECLARE_INTERFACE_(ID3DXRenderToSurface, IUnknown)
  264. {
  265.     // IUnknown
  266.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  267.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  268.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  269.  
  270.     // ID3DXRenderToSurface
  271.     STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE8* ppDevice) PURE;
  272.     STDMETHOD(GetDesc)(THIS_ D3DXRTS_DESC* pDesc) PURE;
  273.  
  274.     STDMETHOD(BeginScene)(THIS_ LPDIRECT3DSURFACE8 pSurface, CONST D3DVIEWPORT8* pViewport) PURE;
  275.     STDMETHOD(EndScene)(THIS) PURE;
  276.  
  277.     STDMETHOD(OnLostDevice)(THIS) PURE;
  278.     STDMETHOD(OnResetDevice)(THIS) PURE;
  279. };
  280.  
  281.  
  282. #ifdef __cplusplus
  283. extern "C" {
  284. #endif //__cplusplus
  285.  
  286. HRESULT WINAPI
  287.     D3DXCreateRenderToSurface(
  288.         LPDIRECT3DDEVICE8       pDevice,
  289.         UINT                    Width,
  290.         UINT                    Height,
  291.         D3DFORMAT               Format,
  292.         BOOL                    DepthStencil,
  293.         D3DFORMAT               DepthStencilFormat,
  294.         LPD3DXRENDERTOSURFACE*  ppRenderToSurface);
  295.  
  296. #ifdef __cplusplus
  297. }
  298. #endif //__cplusplus
  299.  
  300.  
  301.  
  302. ///////////////////////////////////////////////////////////////////////////
  303. // ID3DXRenderToEnvMap:
  304. // --------------------
  305. // This object abstracts rendering to environment maps.  These surfaces 
  306. // do not necessarily need to be render targets.  If they are not, a 
  307. // compatible render target is used, and the result copied into the
  308. // environment map at end scene.
  309. //
  310. // BeginCube, BeginSphere, BeginHemisphere, BeginParabolic -
  311. //    This function initiates the rendering of the environment map.  As
  312. //    parameters, you pass the textures in which will get filled in with
  313. //    the resulting environment map.
  314. //
  315. // Face -
  316. //    Call this function to initiate the drawing of each face.  For each 
  317. //    environment map, you will call this six times.. once for each face 
  318. //    in D3DCUBEMAP_FACES.
  319. //
  320. // End -
  321. //    This will restore all render targets, and if needed compose all the
  322. //    rendered faces into the environment map surfaces.
  323. //
  324. // OnLostDevice, OnResetDevice -
  325. //    Call OnLostDevice() on this object before calling Reset() on the
  326. //    device, so that this object can release any stateblocks and video
  327. //    memory resources.  After Reset(), the call OnResetDevice().
  328. ///////////////////////////////////////////////////////////////////////////
  329.  
  330. typedef struct _D3DXRTE_DESC
  331. {
  332.     UINT        Size;
  333.     D3DFORMAT   Format;
  334.     BOOL        DepthStencil;
  335.     D3DFORMAT   DepthStencilFormat;
  336. } D3DXRTE_DESC;
  337.  
  338.  
  339. typedef interface ID3DXRenderToEnvMap ID3DXRenderToEnvMap;
  340. typedef interface ID3DXRenderToEnvMap *LPD3DXRenderToEnvMap;
  341.  
  342. // {4E42C623-9451-44b7-8C86-ABCCDE5D52C8}
  343. DEFINE_GUID( IID_ID3DXRenderToEnvMap, 
  344. 0x4e42c623, 0x9451, 0x44b7, 0x8c, 0x86, 0xab, 0xcc, 0xde, 0x5d, 0x52, 0xc8);
  345.  
  346.  
  347. #undef INTERFACE
  348. #define INTERFACE ID3DXRenderToEnvMap
  349.  
  350. DECLARE_INTERFACE_(ID3DXRenderToEnvMap, IUnknown)
  351. {
  352.     // IUnknown
  353.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  354.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  355.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  356.  
  357.     // ID3DXRenderToEnvMap
  358.     STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE8* ppDevice) PURE;
  359.     STDMETHOD(GetDesc)(THIS_ D3DXRTE_DESC* pDesc) PURE;
  360.  
  361.     STDMETHOD(BeginCube)(THIS_ 
  362.         LPDIRECT3DCUBETEXTURE8 pCubeTex) PURE;
  363.  
  364.     STDMETHOD(BeginSphere)(THIS_
  365.         LPDIRECT3DTEXTURE8 pTex) PURE;
  366.  
  367.     STDMETHOD(BeginHemisphere)(THIS_ 
  368.         LPDIRECT3DTEXTURE8 pTexZPos,
  369.         LPDIRECT3DTEXTURE8 pTexZNeg) PURE;
  370.  
  371.     STDMETHOD(BeginParabolic)(THIS_ 
  372.         LPDIRECT3DTEXTURE8 pTexZPos,
  373.         LPDIRECT3DTEXTURE8 pTexZNeg) PURE;
  374.  
  375.     STDMETHOD(Face)(THIS_ D3DCUBEMAP_FACES Face) PURE;
  376.     STDMETHOD(End)(THIS) PURE;
  377.  
  378.     STDMETHOD(OnLostDevice)(THIS) PURE;
  379.     STDMETHOD(OnResetDevice)(THIS) PURE;
  380. };
  381.  
  382.  
  383. #ifdef __cplusplus
  384. extern "C" {
  385. #endif //__cplusplus
  386.  
  387. HRESULT WINAPI
  388.     D3DXCreateRenderToEnvMap(
  389.         LPDIRECT3DDEVICE8       pDevice,
  390.         UINT                    Size,
  391.         D3DFORMAT               Format,
  392.         BOOL                    DepthStencil,
  393.         D3DFORMAT               DepthStencilFormat,
  394.         LPD3DXRenderToEnvMap*   ppRenderToEnvMap);
  395.  
  396. #ifdef __cplusplus
  397. }
  398. #endif //__cplusplus
  399.  
  400.  
  401.  
  402. ///////////////////////////////////////////////////////////////////////////
  403. // Shader assemblers:
  404. ///////////////////////////////////////////////////////////////////////////
  405.  
  406. //-------------------------------------------------------------------------
  407. // D3DXASM flags:
  408. // --------------
  409. //
  410. // D3DXASM_DEBUG
  411. //   Generate debug info.
  412. //
  413. // D3DXASM_SKIPVALIDATION
  414. //   Do not validate the generated code against known capabilities and
  415. //   constraints.  This option is only recommended when assembling shaders
  416. //   you KNOW will work.  (ie. have assembled before without this option.)
  417. //-------------------------------------------------------------------------
  418.  
  419. #define D3DXASM_DEBUG           (1 << 0)
  420. #define D3DXASM_SKIPVALIDATION  (1 << 1)
  421.  
  422.  
  423. #ifdef __cplusplus
  424. extern "C" {
  425. #endif //__cplusplus
  426.  
  427. //-------------------------------------------------------------------------
  428. // D3DXAssembleShader:
  429. // -------------------
  430. // Assembles an ascii description of a vertex or pixel shader into 
  431. // binary form.
  432. //
  433. // Parameters:
  434. //  pSrcFile
  435. //      Source file name
  436. //  hSrcModule
  437. //      Module handle. if NULL, current module will be used.
  438. //  pSrcResource
  439. //      Resource name in module
  440. //  pSrcData
  441. //      Pointer to source code
  442. //  SrcDataLen
  443. //      Size of source code, in bytes
  444. //  Flags
  445. //      D3DXASM_xxx flags
  446. //  ppConstants
  447. //      Returns an ID3DXBuffer object containing constant declarations.
  448. //  ppCompiledShader
  449. //      Returns an ID3DXBuffer object containing the object code.
  450. //  ppCompilationErrors
  451. //      Returns an ID3DXBuffer object containing ascii error messages
  452. //-------------------------------------------------------------------------
  453.  
  454. HRESULT WINAPI
  455.     D3DXAssembleShaderFromFileA(
  456.         LPCSTR                pSrcFile,
  457.         DWORD                 Flags,
  458.         LPD3DXBUFFER*         ppConstants,
  459.         LPD3DXBUFFER*         ppCompiledShader,
  460.         LPD3DXBUFFER*         ppCompilationErrors);
  461.  
  462. HRESULT WINAPI
  463.     D3DXAssembleShaderFromFileW(
  464.         LPCWSTR               pSrcFile,
  465.         DWORD                 Flags,
  466.         LPD3DXBUFFER*         ppConstants,
  467.         LPD3DXBUFFER*         ppCompiledShader,
  468.         LPD3DXBUFFER*         ppCompilationErrors);
  469.  
  470. #ifdef UNICODE
  471. #define D3DXAssembleShaderFromFile D3DXAssembleShaderFromFileW
  472. #else
  473. #define D3DXAssembleShaderFromFile D3DXAssembleShaderFromFileA
  474. #endif
  475.  
  476. HRESULT WINAPI
  477.     D3DXAssembleShaderFromResourceA(
  478.         HMODULE               hSrcModule,
  479.         LPCSTR                pSrcResource,
  480.         DWORD                 Flags,
  481.         LPD3DXBUFFER*         ppConstants,
  482.         LPD3DXBUFFER*         ppCompiledShader,
  483.         LPD3DXBUFFER*         ppCompilationErrors);
  484.  
  485. HRESULT WINAPI
  486.     D3DXAssembleShaderFromResourceW(
  487.         HMODULE               hSrcModule,
  488.         LPCWSTR               pSrcResource,
  489.         DWORD                 Flags,
  490.         LPD3DXBUFFER*         ppConstants,
  491.         LPD3DXBUFFER*         ppCompiledShader,
  492.         LPD3DXBUFFER*         ppCompilationErrors);
  493.  
  494. #ifdef UNICODE
  495. #define D3DXAssembleShaderFromResource D3DXAssembleShaderFromResourceW
  496. #else
  497. #define D3DXAssembleShaderFromResource D3DXAssembleShaderFromResourceA
  498. #endif
  499.  
  500. HRESULT WINAPI
  501.     D3DXAssembleShader(
  502.         LPCVOID               pSrcData,
  503.         UINT                  SrcDataLen,
  504.         DWORD                 Flags,
  505.         LPD3DXBUFFER*         ppConstants,
  506.         LPD3DXBUFFER*         ppCompiledShader,
  507.         LPD3DXBUFFER*         ppCompilationErrors);
  508.  
  509.  
  510. #ifdef __cplusplus
  511. }
  512. #endif //__cplusplus
  513.  
  514.  
  515.  
  516. ///////////////////////////////////////////////////////////////////////////
  517. // Misc APIs:
  518. ///////////////////////////////////////////////////////////////////////////
  519.  
  520. #ifdef __cplusplus
  521. extern "C" {
  522. #endif //__cplusplus
  523.  
  524. //-------------------------------------------------------------------------
  525. // D3DXGetErrorString:
  526. // ------------------
  527. // Returns the error string for given an hresult.  Interprets all D3DX and
  528. // D3D hresults.
  529. //
  530. // Parameters:
  531. //  hr
  532. //      The error code to be deciphered.
  533. //  pBuffer
  534. //      Pointer to the buffer to be filled in.
  535. //  BufferLen
  536. //      Count of characters in buffer.  Any error message longer than this
  537. //      length will be truncated to fit.
  538. //-------------------------------------------------------------------------
  539. HRESULT WINAPI
  540.     D3DXGetErrorStringA(
  541.         HRESULT             hr,
  542.         LPSTR               pBuffer,
  543.         UINT                BufferLen);
  544.  
  545. HRESULT WINAPI
  546.     D3DXGetErrorStringW(
  547.         HRESULT             hr,
  548.         LPWSTR              pBuffer,
  549.         UINT                BufferLen);
  550.  
  551. #ifdef UNICODE
  552. #define D3DXGetErrorString D3DXGetErrorStringW
  553. #else
  554. #define D3DXGetErrorString D3DXGetErrorStringA
  555. #endif
  556.  
  557.  
  558.  
  559. #ifdef __cplusplus
  560. }
  561. #endif //__cplusplus
  562.  
  563. #endif //__D3DX8CORE_H__
  564.